<!--
 * @Description: 日程组件
-->
<template>
  <div class="schedule-component">
    <div class="schedule-tabs">
      <div 
        v-for="tab in tabs" 
        :key="tab.value"
        :class="['tab-item', { active: tabValue === tab.value }]"
        @click="handleTabClick(tab.value)"
      >
        {{ tab.label }}
        <el-icon v-if="tab.tip" class="tip-icon" @click.stop="handleTipClick(tab.value)">
          <QuestionFilled />
        </el-icon>
      </div>
    </div>
    
    <div class="schedule-content">
      <div v-if="scheduleList.length === 0" class="empty-state">
        <el-empty description="暂无日程数据" />
      </div>
      
      <div v-else class="schedule-list">
        <div 
          v-for="item in scheduleList" 
          :key="item.id"
          class="schedule-item"
          @click="handleScheduleClick(item)"
        >
          <div class="schedule-time">
            <div class="time-range">{{ item.start }} - {{ item.end }}</div>
            <div v-if="!item.isToday" class="date-info">{{ item.startDate }}</div>
          </div>
          
          <div class="schedule-content-info">
            <div class="schedule-title">{{ item.content }}</div>
            <div v-if="item.place" class="schedule-place">{{ item.place }}</div>
            <div v-if="item.customer" class="schedule-customer">{{ item.customer }}</div>
            
            <div v-if="item.reservationUsers && item.reservationUsers.length > 0" class="reservation-users">
              <div 
                v-for="user in item.reservationUsers" 
                :key="user.id"
                :style="{ color: user.color }"
                class="user-status"
              >
                {{ user.name }} - {{ user.reserveStatusName }}
              </div>
            </div>
          </div>
          
          <div class="schedule-actions">
            <el-tag v-if="item.scheduleType === '0'" type="info">个人日程</el-tag>
            <el-tag v-else-if="item.scheduleType === '1'" type="success">预约服务</el-tag>
            <el-tag v-else-if="item.scheduleType === '2'" type="warning">会议活动</el-tag>
            
            <el-icon v-if="item.isLock" class="lock-icon">
              <Lock />
            </el-icon>
          </div>
        </div>
      </div>
    </div>
    
    <div v-if="tabValue === '团队日程'" class="team-actions">
      <el-button @click="handleTeamClick">选择团队成员</el-button>
    </div>
    
    <div class="add-schedule">
      <el-button type="primary" @click="handleAddClick">添加日程</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElEmpty, ElTag, ElButton, ElIcon } from 'element-plus'
import { QuestionFilled, Lock } from '@element-plus/icons-vue'

interface Props {
  userInfo: any
  powers: string
  scheduleList: any[]
  teamList: any[]
  riliList: any[]
  addTime: string
}

const props = defineProps<Props>()

const emit = defineEmits<{
  onTab: []
  onVerify: []
  onTipsMsg: []
  onTipTab: [string]
  onAdd: []
  onTeam: []
  onSchedule: [any]
}>()

const tabValue = ref('日程管理')

const tabs = [
  { label: '日程管理', value: '日程管理', tip: true },
  { label: '团队日程', value: '团队日程', tip: true },
]

const handleTabClick = (value: string) => {
  tabValue.value = value
  emit('onTab')
}

const handleTipClick = (value: string) => {
  emit('onTipTab', value)
}

const handleScheduleClick = (item: any) => {
  emit('onSchedule', item)
}

const handleTeamClick = () => {
  emit('onTeam')
}

const handleAddClick = () => {
  emit('onAdd')
}

// 暴露给父组件的属性
defineExpose({
  tabValue
})
</script>

<style scoped lang="less">
.schedule-component {
  background: #fff;
  border-radius: 12px;
  margin: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.schedule-tabs {
  display: flex;
  border-bottom: 1px solid #ebeef5;
  
  .tab-item {
    flex: 1;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    
    &.active {
      color: #409eff;
      background-color: #f0f9ff;
      
      &::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 2px;
        background-color: #409eff;
      }
    }
    
    .tip-icon {
      font-size: 14px;
      opacity: 0.6;
      
      &:hover {
        opacity: 1;
      }
    }
  }
}

.schedule-content {
  min-height: 200px;
}

.empty-state {
  padding: 40px 20px;
}

.schedule-list {
  padding: 16px;
}

.schedule-item {
  display: flex;
  padding: 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background-color 0.3s ease;
  
  &:hover {
    background-color: #f9f9f9;
  }
  
  &:last-child {
    border-bottom: none;
  }
  
  .schedule-time {
    width: 120px;
    flex-shrink: 0;
    
    .time-range {
      font-weight: 500;
      color: #409eff;
    }
    
    .date-info {
      font-size: 12px;
      color: #999;
      margin-top: 4px;
    }
  }
  
  .schedule-content-info {
    flex: 1;
    margin: 0 16px;
    
    .schedule-title {
      font-weight: 500;
      margin-bottom: 4px;
    }
    
    .schedule-place,
    .schedule-customer {
      font-size: 12px;
      color: #666;
      margin-bottom: 2px;
    }
    
    .reservation-users {
      margin-top: 8px;
      
      .user-status {
        font-size: 12px;
        margin-bottom: 2px;
      }
    }
  }
  
  .schedule-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    
    .lock-icon {
      color: #f56c6c;
    }
  }
}

.team-actions,
.add-schedule {
  padding: 16px;
  border-top: 1px solid #ebeef5;
  text-align: center;
}
</style>
